package testcases.OpportunitiesBaseDataView.FilterContent;
import resources.testcases.OpportunitiesBaseDataView.FilterContent.FilterContentVerifierHelper;
import tasks.Loading;
import tasks.OpportunitiesBaseData.Filters.Applier;
import tasks.OpportunitiesBaseData.Filters.FilterLayoutTemplate;
import tasks.OpportunitiesBaseData.Filters.GeographyFilter;
import tasks.OpportunitiesBaseData.Filters.SelectBoxVal;
import tasks.OpportunitiesBaseData.Filters.Verifier;
import core.Configurations;
import core.ControlsMapping;
import core.Preconditions;
import core.controls.SelectBox;
import core.enums.Reports;
import core.testcases.TestProjectSuperHelper;
/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class FilterContentVerifier extends FilterContentVerifierHelper
{
	private boolean stepResult = false;
	private Verifier filterVerifier = new Verifier();
	FilterLayoutTemplate filterTemplate = null;
	String brandName = "";
	

	private boolean testCasePreconditions() {
		boolean preconditionResult = false;

		preconditionResult = Preconditions.globalPreconditionCognos(Reports.OpportunitiesBaseDataView);

		return preconditionResult;
	}

    public void executeTest()
    {
        beginTestCase("",
                      "Verify content of "+ this.filterTemplate.getFilterName() + " list boxes for " + brandName + " brand.",
                      "",
                      "Angel Tsvetkov",
                      "",
                      "");
        
        if (testCasePreconditions())
        {     
        	TimeWait(5);
        	
        	stepResult = ControlsMapping.FilterCommonElements.showAll_link.clickLink();
        	setStepResult(stepResult, "Click " + ControlsMapping.FilterCommonElements.showAll_link.getDescriptiveName());
        	
        	Loading.waitToComplete();
        	
        	if(brandName.equals("ITS"))
        	{
            	Applier apply = new Applier();
            	stepResult = apply.applyProductFilter("ITS", null, null, null, null, null, null, null, null, null, null, null,false);
            	setStepResult(stepResult, "Switch to ITS brand in " + ControlsMapping.ProductFilter.BrandOfferingType_listbox.getDescriptiveName());
            	
            	TimeWait(3);
            	stepResult = ControlsMapping.ProductFilter.updateFilter_button.clickButton();
            	setStepResult(stepResult, "Press " + ControlsMapping.ProductFilter.updateFilter_button.getDescriptiveName());
            	
            	Loading.waitToComplete();
        	}
        	
        	for(SelectBoxVal listBox:filterTemplate.getListBoxes())
        	{
        		SelectBox listBoxObj = listBox.getSelectBoxObj();
            	stepResult = filterVerifier.verify(listBox.getValue() , listBoxObj, brandName);
            	setStepResult(stepResult, "Verify " + listBoxObj.getDescriptiveName() + " content!" );
        	}

        	TimeWait(1);
        }
    }
    
    public void testMain(Object[] args)
    {
    	setUp(args);
    	filterTemplate = (FilterLayoutTemplate) args[1];
    	brandName = (String) args[2];
        executeTest();
        reportTestCaseResult(TestProjectSuperHelper.testCase.getTestCaseDescription() , Configurations.PROJECT_NAME);
    }
}

